package com.aaa.web.service.impl.employeeserviceimpl;

import com.aaa.entity.School;
import com.aaa.web.commons.EmpQuery;
import com.aaa.web.commons.Result;
import com.aaa.web.dao.iemployeedao.ISchoolDao;
import com.aaa.web.service.iemployeeservice.ISchoolService;
import com.aaa.web.systemconst.ISystemConst;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class StoreServiceImpl implements ISchoolService {

    @Autowired
    private ISchoolDao storeDao;
    /**
     * @Author yyh
     * @Description //获取门店信息
     * @Date 2018/12/26 9:53 
     * @Param [query]
     * @return java.util.Map
     **/
    @Override
    public Map getStore(EmpQuery query) {
        Map m = new HashMap();
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        m.put("data",storeDao.getStore());
        m.put("count",storeDao.getStoreCount());
        m.put("code",0);
        m.put("msg","");
        return m;
    }
    /**
     * @Author yyh
     * @Description //添加门店
     * @Date 2018/12/26 9:53 
     * @Param [school]
     * @return com.aaa.web.commons.Result
     **/
    @Override
    public Result addSchool(School school) {
        List<Map> list = storeDao.isSchoolExist(school.getSchoolName());
        Result result = new Result();
        if(list!=null&&list.size()>0){
            result.setCode(ISystemConst.DISABLE_CODE);
        }else {
            Integer flag = storeDao.addSchool(school);
            if(flag>0){
                result.setCode(ISystemConst.SUCCESS_CODE);
            }else{
                result.setCode(ISystemConst.DEFEAT_CODE);
            }
        }

        return result;
    }

    @Override
    public Result editSchool(School school) {
        System.out.println(school);
        List<Map> list = storeDao.isSchoolExist(school.getSchoolName());
        Result result = new Result();
        System.out.println(list.size());
        if(list!=null&&list.size()>0){
            result.setCode(ISystemConst.DISABLE_CODE);
        }else {
            Integer flag = storeDao.editSchool(school);
            if(flag>0){
                result.setCode(ISystemConst.SUCCESS_CODE);
            }else{
                result.setCode(ISystemConst.DEFEAT_CODE);
            }
        }
        return result;
    }
}
